package com.javatest.validate;

import javax.validation.Validator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @date 2020-11-10 下午3:41
 */
public class ValidatorTest14 {
    public static void main(String[] args) {
        Room room = new Room();
        room.name = "YourBatman";
        Result<Room> result = new Result<>();
        result.setData(room);

        // 把Result作为属性放进去
        ResultDemo resultDemo = new ResultDemo();
        resultDemo.roomResult = result;

        // 注册自定义的值提取器
        Validator validator = ValidationUtils.obtainValidatorFactory()
                .usingContext()
                .addValueExtractor(new ResultValueExtractor())
                .getValidator();
        ValidationUtils.printViolations(validator.validate(resultDemo));
    }
}
